package com.tanhua.manage.controller;


import com.tanhua.common.utils.NoAuthorization;
import com.tanhua.manage.service.UserFreezeService;
import com.tanhua.manage.service.UserService;
import com.tanhua.manage.vo.Pager;
import com.tanhua.manage.vo.UserFreezeVo;
import com.tanhua.manage.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("management/manage/users")
public class UserController {
    @Autowired
    private UserService userService;

    @Autowired
    private UserFreezeService userFreezeService;

    /**
     * 用户数据翻页
     * @param page           页数
     * @param pageSize       页尺寸
     * @param userId         用户ID
     * @param nickname       昵称
     * @param city           注册城市名称
     * @return
     */
    @GetMapping
    public Pager<UserVo> queryUserList(@RequestParam(value = "page",defaultValue = "1")Integer page,
                                       @RequestParam(value = "pagesize",defaultValue = "10")Integer pageSize,
                                       @RequestParam(value = "id",required = false) Long userId,
                                       @RequestParam(value = "nickname",required = false) String nickname,
                                       @RequestParam(value = "city",required = false) String city){

        //传入分页参数和条件查询参数
        return userService.queryByPage(page,pageSize,userId,nickname,city);
    }




    /**
     * 用户基本资料
     * @param userId
     * @return
     */
    @GetMapping("{userID}")
    @NoAuthorization
    public UserVo queryUserInfo(@PathVariable(name = "userID")Long userId){
        return this.userService.queryUserInfo(userId);
    }

    /**
     * 用户冻结操作
     * @param userFreezeVo
     * @return
     */
    @PostMapping("freeze")
    public Boolean freeze(@RequestBody UserFreezeVo userFreezeVo){
        //从前端传入一个UserFreezeVo对象
        return this.userFreezeService.freeze(userFreezeVo);
    }

    /**
     * 用户解冻操作
     * @param userFreezeVo
     * @return
     */
    @PostMapping("unfreeze")
    public Boolean unfreeze(@RequestBody UserFreezeVo userFreezeVo){
        return userFreezeService.unfreeze(userFreezeVo);
    }
}
